package cn.cxy.demo

import android.app.Service
import android.content.Intent
import android.os.IBinder
import android.util.Log
import kotlin.concurrent.thread

class MyService : Service() {

    override fun onCreate() {
        Log.d("MyService", "onCreate")
        super.onCreate()
    }

    override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
        Log.d("MyService", "onStartCommand")
        thread {
            study()
        }
        return super.onStartCommand(intent, flags, startId)
    }

    private fun study() {
        for (index in 1..100) {
            Log.d("MyService", "我在学习，我在学习，没偷懒")
            Thread.sleep(2000)
        }
    }

    override fun onDestroy() {
        Log.d("MyService", "onDestroy")
        super.onDestroy()
    }

    override fun onBind(intent: Intent?): IBinder? {
        return null
    }
}